// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-6

#ifndef __JOYEDIT_H_COMMON_UI__
#define __JOYEDIT_H_COMMON_UI__

#pragma once

#include "wnd.h"

class CJoyEdit;

//##ModelId=44CF17B800FA
class CJoyEditWrapper : public CRichEditCtrl
{
	DECLARE_DYNAMIC(CJoyEditWrapper)
protected:
public:
	//##ModelId=44CF17B800FC
    CJoyEditWrapper(void);
	//##ModelId=44CF17B800FE
    ~CJoyEditWrapper(void);

	//##ModelId=44CF17B8010A
    CJoyEdit* GetEdit();

	//##ModelId=44CF17B8010B
    void ResetAttrib();
public:
    DECLARE_MESSAGE_MAP()
	//##ModelId=44CF17B8010C
    afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
	//##ModelId=44CF17B80110
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//##ModelId=44CF17B80113
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	//##ModelId=44CF17B8011D
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
};

//##ModelId=44CF17B80128
class CJoyEdit : public CJoyWnd
{
	DECLARE_DYNAMIC(CJoyEdit)
public:
	//##ModelId=44CF17B801A5
    typedef void (CJoyWnd::*PCharEvent)(CJoyEdit* pEdit, UINT nChar, bool& bPass);
protected:
    friend class CJoyEditWrapper;

	//##ModelId=44CF17B80138
    CJoyEditWrapper m_editWrapper;
	//##ModelId=44CF17B8013C
    bool m_multiLine;

	//##ModelId=44CF17B8013E
    CJoyWnd*    m_onCharWnd;
	//##ModelId=44CF17B80149
    PCharEvent  m_onCharEvent;
	//##ModelId=44CF17B8014E
    CJoyWnd*    m_onKeyWnd;
	//##ModelId=44CF17B80153
    PCharEvent  m_onKeyEvent;

	//##ModelId=44CF17B80157
    virtual void CM_LoadSkin(CJoyXmlElement* pSkinElem);
	//##ModelId=44CF17B8015A
    virtual void CM_Draw(Graphics& graph);
public:
	//##ModelId=44CF17B8015D
    CJoyEdit(bool multiLine = false);
	//##ModelId=44CF17B80167
    ~CJoyEdit(void);

	//##ModelId=44CF17B80169
    virtual bool Create(CWnd* parent, const CRect& area);
	//##ModelId=44CF17B8016D
    CRichEditCtrl& GetEditWnd()
    {
        return m_editWrapper;
    }
	//##ModelId=44CF17B80177
    void SetCharEvent(CJoyWnd* pWnd, PCharEvent pOnChar);
	//##ModelId=44CF17B8017A
    void SetKeyEvent(CJoyWnd* pWnd, PCharEvent pOnKey);
	//##ModelId=44CF17B80186
    void SetPasswordChar(CHAR c);
	//##ModelId=44CF17B80188
    void SetText(const CString& text);
	//##ModelId=44CF17B8018A
    CString GetText();
public:
    DECLARE_MESSAGE_MAP()
	//##ModelId=44CF17B8018B
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//##ModelId=44CF17B80196
    afx_msg void OnSize(UINT nType, int cx, int cy);
	//##ModelId=44CF17B8019B
    afx_msg void OnSetFocus(CWnd* pOldWnd);
};

//##ModelId=44CF17B8010A
inline CJoyEdit* CJoyEditWrapper::GetEdit()
{
    return (CJoyEdit*)((char*)this-offsetof(CJoyEdit, m_editWrapper));
}

#endif  // __JOYEDIT_H_COMMON_UI__
